package com.by.yz.activity.base;

/**
 * Created by 123 on 2016/10/5.
 */

import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.Toolbar;
import android.view.MenuItem;

import com.by.yz.App;
import com.by.yz.common.ExitAppUtils;
import com.by.yz.common.MFGT;
import com.by.yz.custom.ToolBarHelper;

public abstract class BaseActivity extends AppCompatActivity {
    private ToolBarHelper mToolBarHelper;
    public Toolbar toolbar;
    private App application;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        application = (App)getApplication();
        application.addActivity(this);
    }

    @Override
    public void setContentView(int layoutResID) {

        mToolBarHelper = new ToolBarHelper(this, layoutResID);
        toolbar = mToolBarHelper.getToolBar();
        ExitAppUtils.getInstance().addActivity(this);
        setContentView(mToolBarHelper.getContentView()); /*把 toolbar 设置到Activity 中*/
        setSupportActionBar(toolbar);
      //  getSupportActionBar().setHomeAsUpIndicator(R.drawable.ic_menu);
        getSupportActionBar().setDisplayHomeAsUpEnabled(true);
        //getSupportActionBar().setTitle("aaaaa");
        /*自定义的一些操作*/
        onCreateCustomToolBar(toolbar);
    }

    public void onCreateCustomToolBar(Toolbar toolbar) {
        toolbar.setContentInsetsRelative(0, 0);
    }

    @Override
    public boolean onOptionsItemSelected(MenuItem item) {
        if (item.getItemId() == android.R.id.home) {
            MFGT.finish(this);
            return true;
        }
        return super.onOptionsItemSelected(item);
    }

    @Override
    public void onBackPressed() {
        super.onBackPressed();
        MFGT.finish(this);
    }

    public  void setToolbarTitle(String title){
        getSupportActionBar().setTitle(title);
    };
    public  void setToolbarLeftIcon(int id){
        getSupportActionBar().setHomeAsUpIndicator(id);
    };
    public  void setToolbarRightIcom(int id){

    }
}